package com.le.tester.leetcode;

import com.le.tester.leetcode.common.TreeNode;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * 描述：中序遍历
 */
public class MiddleTree {
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> result = new ArrayList<>();
        //开栈
        Stack<TreeNode> treeNodes = new Stack<>();
        while (null != root || !treeNodes.isEmpty()) {
            while (null != root) {
                treeNodes.push(root);
                root = root.left;
            }
            root = treeNodes.pop();
            result.add(root.val);
            root = root.right;
        }
        return result;
    }
}
